package tools;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.geom.Ellipse2D;

import core.DrawContext;
import core.Object2D;

public class EllipseTool extends GeometricTool {
	
	private EllipseProxy proxy = new EllipseProxy();
	
	private class EllipseProxy implements Object2D{

		@Override
		public void draw(Graphics2D g2) {
			
			if(!firstSelected){
				return;
			}
			
			BasicStroke stroke = new BasicStroke(getLineSize());
			
			g2.setStroke(stroke);
			g2.setColor(getColor());
			
			Ellipse2D.Double ellipse = new Ellipse2D.Double(
					firstPoint.x, firstPoint.y, 
					Math.abs(firstPoint.x - secondPoint.x),
					Math.abs(firstPoint.y - secondPoint.y));
		
			if(isFill()){
				g2.fill(ellipse);
			}
			else{
				g2.draw(ellipse);
			}
		}
		
	}

	@Override
	public Object2D getProxy() {
		return proxy;
	}

	@Override
	public void draw(Point p1, Point p2, DrawContext ctx) {
		
		ctx.getGraphics().setColor(getColor());
		
		BasicStroke stroke = new BasicStroke(getLineSize());
		
		ctx.getGraphics().setStroke(stroke);
		
		Ellipse2D.Double ellipse = new Ellipse2D.Double(
				firstPoint.x, firstPoint.y, 
				Math.abs(firstPoint.x - secondPoint.x),
				Math.abs(firstPoint.y - secondPoint.y));
	
		if(isFill()){
			ctx.getGraphics().fill(ellipse);
		}else{
			ctx.getGraphics().draw(ellipse);
		}
	}
	
}
